from flask import Flask, render_template
from flask_cors import CORS
#引用数据库配置文件
import config
#引用数据库
from user.index import *
from student.index import *
from score.index import *
from class_room.index import *
from opinions.index import *
from course.index import *
from dormitory.index import *
from data.index import *
from task.index import *

app = Flask(__name__)

CORS(app, supports_credentials=True)
app.config.from_object(config)
app.config['JSON_AS_ASCII'] = False
db.init_app(app)

# 注册
app.register_blueprint(user, url_prefix="/")
app.register_blueprint(student, url_prefix="/")
app.register_blueprint(score, url_prefix="/")
app.register_blueprint(class_room, url_prefix="/")
app.register_blueprint(opinions, url_prefix="/")
app.register_blueprint(course, url_prefix="/")
app.register_blueprint(dormitory, url_prefix="/")
app.register_blueprint(data, url_prefix="/")
app.register_blueprint(task, url_prefix="/")

# session所需加密字段
app.config["SECRET_KEY"] = 'TPmi4aLWRbyVq8zu9v82dWYW1'
# 开启debug调试
app.run(debug=True)
#首页
@app.route('/', methods=['GET'])
def index():
    return render_template('login.html')
#文件上传页面
@app.route('/upload')
def index1():
    return render_template('index.html')
#文件成功上传提示页面
@app.route('/success', methods=['POST'])
def success():
    if request.method == 'POST':
        f = request.files['file']
        f.save(f.filename)
        return render_template('success.html', name=f.filename)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)
